package cn.tedu.luban.order.main.repository;

import cn.tedu.luban.order.main.converter.OrderConverter;
import cn.tedu.luban.order.main.dao.OrderDAO;
import cn.tedu.luban.order.protocol.bo.OrderBO;
import cn.tedu.luban.order.protocol.dos.OrderDO;
import cn.tedu.luban.order.protocol.param.OrderCreateParam;
import cn.tedu.luban.order.protocol.param.OrderParam;
import cn.tedu.luban.order.protocol.query.AdminOrderListQuery;
import cn.tedu.luban.order.protocol.query.FrontOrderDBPagerQuery;
import cn.tedu.luban.order.protocol.query.FrontOrderListQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderRepoImpl implements OrderRepository{

    @Autowired
    private OrderConverter orderConverter;
    @Autowired
    private OrderDAO orderDAO;

    @Override
    public void saveOrder(OrderCreateParam param) {
        OrderDO orderDO = orderConverter.param2do(param);
        orderDAO.saveOrder(orderDO);
    }

    @Override
    public Long countOrders(FrontOrderListQuery query) {

        FrontOrderDBPagerQuery dbQuery = orderConverter.query2dbQuery(query);
        return orderDAO.countFrontOrders(dbQuery);
    }

    @Override
    public List<OrderBO> queryOrders(FrontOrderListQuery query) {

        FrontOrderDBPagerQuery dbQuery = orderConverter.query2dbQuery(query);
        List<OrderDO> dos = orderDAO.queryFrontOrders(dbQuery);
        return orderConverter.dos2bos(dos);
    }


    @Override
    public Long countOrders(AdminOrderListQuery adminOrderListQuery) {
        return null;
    }

    @Override
    public List<OrderBO> queryOrders(AdminOrderListQuery orderBOQuery) {
        return null;
    }

    @Override
    public OrderBO getOrderById(Long id) {
        return null;
    }



    @Override
    public OrderBO getOrderByOrderNo(String no) {
        OrderDO orderDO = orderDAO.selectOrderByOrderNo(no);
        return orderConverter.do2bo(orderDO);
    }

    @Override
    public void closeOrder(OrderParam param) {

    }

    @Override
    public void updateStatus(OrderParam param) {
        OrderDO orderDO = orderConverter.param2do(param);
        orderDAO.updateOrderStatusByOrderNo(orderDO);
    }
}
